<html>
<head>
<#include "common/common.html"/>
<meta charset="UTF-8">
<#include "common/css_js.html"/> <#include "common/fupage.html" />
<#include "common/artdialog.html"/>
<script type="text/javascript">
$(document).ready(function() {
	var backUrl = base + "/role/";
	$("#add").bind("click", function() {
		var pass =  $("#editForm").validationEngine("validate");
		if(!pass){
			return;
		}
		var name = $("#name").val();
		var remark = $("#remark").val();
		var privilegeStr = "";
		var id=$("#id").val();
		$("input[name='privilegeStr']:checked").each(function(i, str) {
			console.log(i + "," + $(this).val());
			privilegeStr+=$(this).val()+",";
		});
		post(base + "/role/doupdate.js?v=${bv}on", {
			"name" : name,
			"remark" : remark,
			"privilegeStr" : privilegeStr,
			"id":id
		}, function(data) {
			if (data.code == 1) {
				var d = dialog({
					title : defaultAlertTitle,
					content : '更新角色成功',
					cancel : false,
					ok : function() {
						load(backUrl);
					}
				});
				d.show();
			}
		});
	});

	cancelBind(backUrl);
});
</script>
</head>
<body>
	<form id="editForm" class="validationEngine">
		<table>
			<tr>
				<td>角色名:</td>
				<td><input type="text" name="name" id="name" maxlength="20" class="validate[required]" value="${role.name}" >
				</input></td>
			</tr>
			<tr>
				<td>备注:</td>
				<td><input type="text" name="remark" id="remark" class="validate[required]" value="${role.remark}"></input></td>
			</tr>

			<#list privilegeList as item> <#if (item_index+1)%4 ==1>
			<tr>
				<td>${item.name}<input type="checkbox" name="privilegeStr"
					value="${item.acl}"<#if
					item.checked>checked="checked}"</#if>/>&nbsp;
				</td> <#elseif (item_index+1)%4 ==0>
				<td>${item.name}<input type="checkbox" name="privilegeStr"
					value="${item.acl}"<#if
					item.checked>checked="checked}"</#if>/>&nbsp;
			</tr>
			<#else>
			<td>${item.name}<input type="checkbox" name="privilegeStr"
				value="${item.acl}"<#if
				item.checked>checked="checked}"</#if>/>&nbsp; </#if> </#list> <#if
				privilegeList?size%4!=0>
			</tr>
			</#if>
			<tr>
				<td><#include "common/form_submit_button.html"/></td>
			</tr>
			<input type="hidden" id="id" value="${role.id}" />
		</table>
	</form>
</body>
</html>